﻿using Microsoft.EntityFrameworkCore;
using System;
using FF14TreasureDiggingTool.DataAccess.ApplicationDbContext.EntityTypeConfiguration;
using FF14TreasureDiggingTool.DataAccess.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;

namespace FF14TreasureDiggingTool.DataAccess.ApplicationDbContext; 

public class ApplicationContext : DbContext
{
    //public string DbPath { get; }
    private readonly IConfiguration _configuration;
    public ApplicationContext(DbContextOptions<ApplicationContext> options,IConfiguration configuration) : base(options)
    {
        //var folder = Environment.SpecialFolder.LocalApplicationData;
        //var path = Environment.GetFolderPath(folder);
        //var path = System.IO.Directory.GetCurrentDirectory();
        //DbPath = System.IO.Path.Join(path, "FTDTDB.db");
        _configuration = configuration;
    }

    
    protected override void OnConfiguring(DbContextOptionsBuilder options)
        //=> options.UseSqlite($"Data Source={DbPath}");
        => options.UseSqlite(_configuration.GetSection("ConnString").Value);
    

    public DbSet<CustomRule> CustomRules { get; set; }
    public DbSet<FloorInfo> FloorInfos { get; set; }
    public DbSet<RouteOption> RouteOptions { get; set; }
    public DbSet<SpecialEvent> SpecialEvents { get; set; }
    public DbSet<DungeonsRecord> DungeonsRecords { get; set; }


    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.ApplyConfiguration(new CustomRuleEntityTypeConfiguration());
        modelBuilder.ApplyConfiguration(new FloorInfoEntityTypeConfiguration());
    }
}